import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-02-06
 * Time: 20:42
 */
public class test1 {
    /**
     * LeetCode 771  宝石与石头
     */

    public int numJewelsInStones(String jewels, String stones) {
        // 记录结果
        int ret = 0;
        Map<Character,Integer> hash = new HashMap<>();

        for(int i=0;i<jewels.length();i++){
            hash.put(jewels.charAt(i),hash.getOrDefault(hash.get(jewels.charAt(i)),0)+1);
        }

        for(int i=0;i<stones.length();i++){
            if(hash.containsKey(stones.charAt(i))){
                ret++;
            }
        }
        return ret;
    }
}
